package com.ruoyi.patrol.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.patrol.domain.PatrolPath;
import com.ruoyi.patrol.service.IPatrolPathService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡查路线Controller
 * 
 * @author yepanpan
 * @date 2025-05-08
 */
@RestController
@RequestMapping("/patrol/path")
public class PatrolPathController extends BaseController
{
    @Autowired
    private IPatrolPathService patrolPathService;

    /**
     * 查询巡查路线列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:path:list')")
    @GetMapping("/list")
    public TableDataInfo list(PatrolPath patrolPath)
    {
        startPage();
        List<PatrolPath> list = patrolPathService.selectPatrolPathList(patrolPath);
        return getDataTable(list);
    }

    /**
     * 导出巡查路线列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:path:export')")
    @Log(title = "巡查路线", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PatrolPath patrolPath)
    {
        List<PatrolPath> list = patrolPathService.selectPatrolPathList(patrolPath);
        ExcelUtil<PatrolPath> util = new ExcelUtil<PatrolPath>(PatrolPath.class);
        util.exportExcel(response, list, "巡查路线数据");
    }


    /**
     * 获取巡查路线详细信息
     */
    @PreAuthorize("@ss.hasPermi('patrol:path:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(patrolPathService.selectPatrolPathById(id));
    }

    /**
     * 新增巡查路线
     */
    @PreAuthorize("@ss.hasPermi('patrol:path:add')")
    @Log(title = "巡查路线", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody PatrolPath patrolPath)
    {
                patrolPath.setCreateBy(getUsername());
        return toAjax(patrolPathService.insertPatrolPath(patrolPath));
    }

    /**
     * 修改巡查路线
     */
    @PreAuthorize("@ss.hasPermi('patrol:path:edit')")
    @Log(title = "巡查路线", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody PatrolPath patrolPath)
    {
                patrolPath.setUpdateBy(getUsername());
        return toAjax(patrolPathService.updatePatrolPath(patrolPath));
    }

    /**
     * 删除巡查路线
     */
    @PreAuthorize("@ss.hasPermi('patrol:path:remove')")
    @Log(title = "巡查路线", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(patrolPathService.deletePatrolPathByIds(ids));
    }
}
